# Maintainer: Artem Konoplin <konoplin@gmail.com>

_realname=mlt
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=6.22.1
pkgrel=1
pkgdesc="An open source multimedia framework (mingw-w64)"
arch=('any')
url="https://www.mltframework.org"
license=('GPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-dlfcn"
             "${MINGW_PACKAGE_PREFIX}-SDL2"
             "${MINGW_PACKAGE_PREFIX}-fftw"
             "${MINGW_PACKAGE_PREFIX}-ffmpeg"
             "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2")

depends=("${MINGW_PACKAGE_PREFIX}-SDL2"
         "${MINGW_PACKAGE_PREFIX}-fftw"
         "${MINGW_PACKAGE_PREFIX}-ffmpeg"
         "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2")

#options=('strip' 'staticlibs')
source=("https://github.com/mltframework/mlt/archive/v$pkgver.tar.gz"
        "010-mlt-6.22.1-fix-msys-cmake.patch")
sha256sums=('a3debdf0b8811f0d20c902cc3df3d05dad7d3ff36d1db16c0a7338d0d5989998'
            '68aec02e1987919935f115cefbd0ce69e7ca1714612b7b11dc757de6efe8a92f')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/010-mlt-6.22.1-fix-msys-cmake.patch"
}

build() {
  build_dir=${srcdir}/build-${MINGW_CHOST}
  [[ -d ${build_dir} ]] && rm -rf ${build_dir}
  mkdir -p ${build_dir}
  cd ${build_dir}

  # makepkg-mingw does not set the MSYSTEM_CARCH variable, so we use CARCH instead

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake -G"MSYS Makefiles" -DARCH=${CARCH} -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} "${srcdir}/${_realname}-${pkgver}"

  make -j$(nproc)
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR="$pkgdir" install
}
